<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis 标签详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #2d3748;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #f8f9fa;
            border-left: 4px solid #4fd1c5;
            color: #2d3748;
        }
        .tag-highlight {
            color: #e53e3e;
            font-weight: 500;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .tag-icon {
            color: #4fd1c5;
            margin-right: 8px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">MyBatis 核心标签解析</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">探索轻量级持久层框架的精髓</p>
            <div class="max-w-3xl mx-auto bg-white bg-opacity-20 rounded-lg p-6 backdrop-blur-sm">
                <p class="text-lg">MyBatis 是一个轻量级的持久层框架，它通过使用 XML 和注解的方式将 SQL 语句与 Java 方法进行映射和绑定。MyBatis 的核心功能之一是使用 XML 标签来构建和管理 SQL 语句，从而实现对数据库的动态访问和操作。</p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Tags Overview -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center border-b-2 border-gray-200 pb-4">MyBatis 常用标签分类</h2>
            
            <div class="grid md:grid-cols-3 gap-8">
                <!-- Basic Tags Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-blue-600 p-4 text-white">
                        <h3 class="text-xl font-bold flex items-center">
                            <i class="fas fa-tags tag-icon"></i>基本标签
                        </h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-blue-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-blue-700">&lt;select&gt;</span>: 查询操作</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-blue-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-blue-700">&lt;insert&gt;</span>: 插入操作</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-blue-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-blue-700">&lt;update&gt;</span>: 更新操作</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-blue-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-blue-700">&lt;delete&gt;</span>: 删除操作</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Dynamic SQL Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-purple-600 p-4 text-white">
                        <h3 class="text-xl font-bold flex items-center">
                            <i class="fas fa-code-branch tag-icon"></i>动态SQL标签
                        </h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-purple-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-purple-700">&lt;if&gt;</span>: 条件判断</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-purple-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-purple-700">&lt;choose&gt;</span>: 条件选择</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-purple-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-purple-700">&lt;where&gt;</span>/<span class="font-semibold text-purple-700">&lt;set&gt;</span>: SQL片段处理</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Advanced Tags Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-teal-600 p-4 text-white">
                        <h3 class="text-xl font-bold flex items-center">
                            <i class="fas fa-star tag-icon"></i>高级标签
                        </h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-teal-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-teal-700">&lt;foreach&gt;</span>: 集合迭代</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-teal-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-teal-700">&lt;resultMap&gt;</span>: 复杂映射</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-angle-right text-teal-500 mt-1 mr-2"></i>
                                <span><span class="font-semibold text-teal-700">&lt;sql&gt;</span>/<span class="font-semibold text-teal-700">&lt;include&gt;</span>: SQL重用</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Tags Details -->
        <section>
            <!-- Basic Tags -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b-2 border-gray-200 pb-4">基本标签详解</h2>
                
                <!-- select -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-blue-100 p-4 border-l-4 border-blue-500">
                        <h3 class="text-xl font-bold text-blue-800 flex items-center">
                            <i class="fas fa-search tag-icon"></i>
                            <span>&lt;select&gt; - 查询操作</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于定义查询操作的 SQL 语句。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">id</span>: SQL 语句的唯一标识符，与 Mapper 接口中的方法名对应</li>
                                <li><span class="font-medium">resultType</span>: 指定返回结果的 Java 类型</li>
                                <li><span class="font-medium">resultMap</span>: 指定自定义结果映射</li>
                                <li><span class="font-medium">parameterType</span>: 指定输入参数的 Java 类型</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;select id="selectUserById" resultType="User" parameterType="int"&gt;
  SELECT * FROM users WHERE id = #{id}
&lt;/select&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">#{id}</span>: MyBatis 会将参数 id 的值绑定到 SQL 中的 ? 占位符上，并自动进行类型转换</li>
                                <li><span class="tag-highlight">resultType="User"</span>: MyBatis 会将查询结果自动映射为 User 类的实例</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- insert -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-green-100 p-4 border-l-4 border-green-500">
                        <h3 class="text-xl font-bold text-green-800 flex items-center">
                            <i class="fas fa-plus-circle tag-icon"></i>
                            <span>&lt;insert&gt; - 插入操作</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于定义插入操作的 SQL 语句。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">id</span>: SQL 语句的唯一标识符</li>
                                <li><span class="font-medium">parameterType</span>: 指定输入参数的 Java 类型</li>
                                <li><span class="font-medium">useGeneratedKeys</span>: 是否使用数据库自动生成的主键</li>
                                <li><span class="font-medium">keyProperty</span>: 指定主键对应的 Java 属性名</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id"&gt;
  INSERT INTO users (name, email) VALUES (#{name}, #{email})
&lt;/insert&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">useGeneratedKeys="true"</span>: 启用自动生成主键</li>
                                <li><span class="tag-highlight">keyProperty="id"</span>: 指定主键生成后映射到 User 对象的 id 属性</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- update -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-yellow-100 p-4 border-l-4 border-yellow-500">
                        <h3 class="text-xl font-bold text-yellow-800 flex items-center">
                            <i class="fas fa-edit tag-icon"></i>
                            <span>&lt;update&gt; - 更新操作</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于定义更新操作的 SQL 语句。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">id</span>: SQL 语句的唯一标识符</li>
                                <li><span class="font-medium">parameterType</span>: 指定输入参数的 Java 类型</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;update id="updateUser" parameterType="User"&gt;
  UPDATE users SET name = #{name}, email = #{email} WHERE id = #{id}
&lt;/update&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">#{name}</span> 和 <span class="tag-highlight">#{email}</span>: MyBatis 将 User 对象的 name 和 email 属性绑定到 SQL 占位符中</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- delete -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-red-100 p-4 border-l-4 border-red-500">
                        <h3 class="text-xl font-bold text-red-800 flex items-center">
                            <i class="fas fa-trash-alt tag-icon"></i>
                            <span>&lt;delete&gt; - 删除操作</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于定义删除操作的 SQL 语句。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">id</span>: SQL 语句的唯一标识符</li>
                                <li><span class="font-medium">parameterType</span>: 指定输入参数的 Java 类型</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;delete id="deleteUser" parameterType="int"&gt;
  DELETE FROM users WHERE id = #{id}
&lt;/delete&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">parameterType="int"</span>: MyBatis 将整数参数 id 绑定到 SQL 中的 #{id} 占位符</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Dynamic SQL Tags -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b-2 border-gray-200 pb-4">动态SQL标签详解</h2>
                
                <!-- if -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-purple-100 p-4 border-l-4 border-purple-500">
                        <h3 class="text-xl font-bold text-purple-800 flex items-center">
                            <i class="fas fa-code-branch tag-icon"></i>
                            <span>&lt;if&gt; - 条件判断</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于根据条件动态构建 SQL 语句。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">test</span>: 指定条件表达式，支持 OGNL 表达式</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;select id="selectUserByCondition" resultType="User"&gt;
  SELECT * FROM users WHERE 1=1
  &lt;if test="name != null"&gt;
    AND name = #{name}
  &lt;/if&gt;
  &lt;if test="email != null"&gt;
    AND email = #{email}
  &lt;/if&gt;
&lt;/select&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">test="name != null"</span>: 如果 name 参数不为空，则添加对应的 SQL 条件</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- choose/when/otherwise -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-indigo-100 p-4 border-l-4 border-indigo-500">
                        <h3 class="text-xl font-bold text-indigo-800 flex items-center">
                            <i class="fas fa-project-diagram tag-icon"></i>
                            <span>&lt;choose&gt;, &lt;when&gt;, &lt;otherwise&gt; - 条件选择</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>类似于 Java 中的 switch 语句，用于根据不同条件选择 SQL 片段。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">&lt;when&gt; 的 test</span>: 条件表达式</li>
                                <li><span class="font-medium">&lt;otherwise&gt;</span>: 没有匹配到任何 &lt;when&gt; 时执行的默认 SQL 片段</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;select id="selectUserByStatus" resultType="User"&gt;
  SELECT * FROM users
  &lt;where&gt;
    &lt;choose&gt;
      &lt;when test="status == 'active'"&gt;
        status = 'active'
      &lt;/when&gt;
      &lt;when test="status == 'inactive'"&gt;
        status = 'inactive'
      &lt;/when&gt;
      &lt;otherwise&gt;
        status = 'unknown'
      &lt;/otherwise&gt;
    &lt;/choose&gt;
  &lt;/where&gt;
&lt;/select&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">&lt;choose&gt;</span>: 在 status 等于不同值时选择不同的 SQL 条件</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- trim/where/set -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-pink-100 p-4 border-l-4 border-pink-500">
                        <h3 class="text-xl font-bold text-pink-800 flex items-center">
                            <i class="fas fa-cut tag-icon"></i>
                            <span>&lt;trim&gt;, &lt;where&gt;, &lt;set&gt; - SQL片段处理</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于动态去除或添加 SQL 片段。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">&lt;trim&gt;</span>: 用于去除或添加前后缀</li>
                                <li><span class="font-medium">&lt;where&gt;</span>: 自动处理 SQL 中的 WHERE 关键字</li>
                                <li><span class="font-medium">&lt;set&gt;</span>: 用于 UPDATE 语句中动态添加 SET 子句</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;update id="updateUser" parameterType="User"&gt;
  UPDATE users
  &lt;set&gt;
    &lt;if test="name != null"&gt;
      name = #{name},
    &lt;/if&gt;
    &lt;if test="email != null"&gt;
      email = #{email}
    &lt;/if&gt;
  &lt;/set&gt;
  WHERE id = #{id}
&lt;/update&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">&lt;set&gt;</span>: 自动处理 SQL 语句中 SET 子句末尾的逗号</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Advanced Tags -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b-2 border-gray-200 pb-4">高级标签详解</h2>
                
                <!-- foreach -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-teal-100 p-4 border-l-4 border-teal-500">
                        <h3 class="text-xl font-bold text-teal-800 flex items-center">
                            <i class="fas fa-redo tag-icon"></i>
                            <span>&lt;foreach&gt; - 集合迭代</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于迭代集合类型参数，构建批量处理 SQL。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">collection</span>: 指定要迭代的集合</li>
                                <li><span class="font-medium">item</span>: 迭代时当前元素的别名</li>
                                <li><span class="font-medium">open</span>: 在结果前添加的内容</li>
                                <li><span class="font-medium">close</span>: 在结果后添加的内容</li>
                                <li><span class="font-medium">separator</span>: 元素之间的分隔符</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;select id="selectUserByIds" resultType="User"&gt;
  SELECT * FROM users WHERE id IN
  &lt;foreach collection="list" item="id" open="(" separator="," close=")"&gt;
    #{id}
  &lt;/foreach&gt;
&lt;/select&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">&lt;foreach&gt;</span>: 迭代 list 集合，生成以逗号分隔的 id 列表</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- resultMap -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-orange-100 p-4 border-l-4 border-orange-500">
                        <h3 class="text-xl font-bold text-orange-800 flex items-center">
                            <i class="fas fa-map-signs tag-icon"></i>
                            <span>&lt;resultMap&gt; - 复杂映射</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于定义复杂的结果映射，处理字段与属性名称不一致的情况。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">id</span>: 结果映射的唯一标识符</li>
                                <li><span class="font-medium">type</span>: 结果映射的目标 Java 类</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;resultMap id="userResultMap" type="User"&gt;
  &lt;id property="id" column="user_id"/&gt;
  &lt;result property="name" column="user_name"/&gt;
  &lt;result property="email" column="user_email"/&gt;
&lt;/resultMap&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">&lt;resultMap&gt;</span>: 将数据库表字段映射到 Java 对象属性，支持复杂结构映射</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- sql/include -->
                <div class="mb-10 bg-white rounded-lg shadow-md overflow-hidden">
                    <div class="bg-cyan-100 p-4 border-l-4 border-cyan-500">
                        <h3 class="text-xl font-bold text-cyan-800 flex items-center">
                            <i class="fas fa-puzzle-piece tag-icon"></i>
                            <span>&lt;sql&gt; 和 &lt;include&gt; - SQL重用</span>
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">用途</h4>
                            <p>用于定义可重用的 SQL 片段，避免重复代码。</p>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">主要属性</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="font-medium">&lt;sql&gt;</span>: 定义 SQL 片段</li>
                                <li><span class="font-medium">&lt;include&gt;</span>: 引入已定义的 SQL 片段</li>
                            </ul>
                        </div>
                        <div class="mb-4">
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">示例代码</h4>
                            <pre class="code-block p-4 rounded-lg overflow-x-auto"><code>&lt;sql id="userColumns"&gt;
  user_id, user_name, user_email
&lt;/sql&gt;

&lt;select id="selectUser" resultType="User"&gt;
  SELECT &lt;include refid="userColumns"/&gt; FROM users WHERE id = #{id}
&lt;/select&gt;</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-gray-700">解析</h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li><span class="tag-highlight">&lt;sql&gt;</span>: 定义常用的 SQL 字段</li>
                                <li><span class="tag-highlight">&lt;include&gt;</span>: 在查询中引入定义的 SQL 字段，减少重复代码</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Application Scenarios -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-8 text-center border-b-2 border-gray-200 pb-4">MyBatis 标签的实际应用场景</h2>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <!-- Scenario 1 -->
                    <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 p-3 rounded-full mr-4">
                                <i class="fas fa-cogs text-blue-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">灵活的 SQL 构建</h3>
                        </div>
                        <div class="pl-16">
                            <p class="mb-3"><span class="font-semibold">场景</span>: 需要根据用户输入动态生成 SQL 查询时，使用 &lt;if&gt;、&lt;choose&gt; 等标签。</p>
                            <p><span class="font-semibold">优势</span>: 提高了 SQL 构建的灵活性，支持复杂查询场景。</p>
                        </div>
                    </div>
                    
                    <!-- Scenario 2 -->
                    <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-green-100 p-3 rounded-full mr-4">
                                <i class="fas fa-database text-green-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">批量操作</h3>
                        </div>
                        <div class="pl-16">
                            <p class="mb-3"><span class="font-semibold">场景</span>: 执行批量插入、更新或删除操作时，使用 &lt;foreach&gt; 标签。</p>
                            <p><span class="font-semibold">优势</span>: 简化了批量操作的 SQL 构建，提高了操作的效率。</p>
                        </div>
                    </div>
                    
                    <!-- Scenario 3 -->
                    <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-purple-100 p-3 rounded-full mr-4">
                                <i class="fas fa-map-marked-alt text-purple-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">结果映射处理</h3>
                        </div>
                        <div class="pl-16">
                            <p class="mb-3"><span class="font-semibold">场景</span>: 数据库字段与 Java 对象属性名称不一致时，使用 &lt;resultMap&gt; 进行复杂映射。</p>
                            <p><span class="font-semibold">优势</span>: 提供了灵活的结果映射机制，支持复杂数据结构的处理。</p>
                        </div>
                    </div>
                    
                    <!-- Scenario 4 -->
                    <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-teal-100 p-3 rounded-full mr-4">
                                <i class="fas fa-recycle text-teal-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">SQL 片段重用</h3>
                        </div>
                        <div class="pl-16">
                            <p class="mb-3"><span class="font-semibold">场景</span>: 多个 SQL 语句中重复使用相同的字段或条件时，使用 &lt;sql&gt; 和 &lt;include&gt; 标签。</p>
                            <p><span class="font-semibold">优势</span>: 避免了 SQL 代码的重复，提高了代码的维护性。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Mermaid Diagram -->
            <div class="mb-16 bg-white p-8 rounded-lg shadow-md">
                <h2 class="text-3xl font-bold mb-6 text-center">MyBatis 标签关系图</h2>
                <div class="mermaid">
                    graph TD
                        A[MyBatis XML 标签] --> B[基本标签]
                        A --> C[动态SQL标签]
                        A --> D[高级标签]
                        
                        B --> B1[select]
                        B --> B2[insert]
                        B --> B3[update]
                        B --> B4[delete]
                        
                        C --> C1[if]
                        C --> C2[choose/when/otherwise]
                        C --> C3[where/set/trim]
                        
                        D --> D1[foreach]
                        D --> D2[resultMap]
                        D --> D3[sql/include]
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4 text-center">
            <h3 class="text-xl font-semibold mb-2">技术小馆</h3>
            <p class="mb-4">探索技术世界的知识殿堂</p>
            <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors duration-200">http://www.yuque.com/jtostring</a>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>